/*
 * Copyright (c) Shenzhen 7th Road Technical Co., Ltd
 * Technical Support dept.
 * http://www.7road.com
 */
package com.sz7thrd.ts.ccu.handler;

import java.util.Date;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;

/**
 * @author able
 * @date 2011-12-14
 * ===============================
 * 
 * 
 */
public class MyHandler extends IoHandlerAdapter {
    
    @Override
    public void exceptionCaught(IoSession session, Throwable cause)
            throws Exception {
        
        cause.printStackTrace();
    }
    
    @Override
    public void messageReceived(IoSession session, Object message)
            throws Exception {
        
        String str = message.toString();
        if (str.trim().equalsIgnoreCase("quit")) {
            session.close();
            return;
        }
        
        Date date = new Date();
        session.write(date.toString());
    }
    
    @Override
    public void messageSent(IoSession session, Object message) throws Exception {
        System.out.println("=> messageSent:"+message.toString());
    }
    @Override
        public void sessionCreated(IoSession session) throws Exception {
        System.out.println("=> sessionCreated");
    }

    @Override
    public void sessionOpened(IoSession session) throws Exception {
        System.out.println("=> sessionOpened");
    }

    @Override
    public void sessionClosed(IoSession session) throws Exception {
        System.out.println("=> sessionClosed");
    }

    @Override
    public void sessionIdle(IoSession session, IdleStatus status)
            throws Exception {
        System.out.println("=> sessionIdle");
    }
}
